<?php
/**
 * 模板视图
 *
 * @package if
 * @subpackage view
 * @since 1.0
 */
abstract class ITplView extends IAbstractView {
	public abstract function __construct($tpl = null, $ext = null);
	
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $dir
	 * @param unknown_type $tpl 已经带扩展名的模板文件
	 * @param unknown_type $ext
	 * @param unknown_type $fuzzy
	 * @return IFile
	 */
	function find($dir, $tpl, $ext, $fuzzy = true) {
		$dir = IApplication::singleton()->relativeFile($dir);
		if (!$dir->exists()) {
			return null;
		}
		
		$file = new IFile($dir->absPath() . "/" . $tpl);
		if ($file->exists() && $file->isFile()) {
			return $file;
		}
		
		if (!$fuzzy) {
			return null;
		}
		
		//尝试模糊查找
		$lists = $dir->lists("*" . $ext, true);
		$path = strtolower(str_replace("_", "", $file->path()));
		foreach ($lists as $tplFile) {
			if ($path == strtolower(str_replace("_", "", $tplFile->absPath()))) {
				return $tplFile;
			}
		}
		
		return null;
	}
}

?>